/**
 * File name: Edge.java Author: Willard Wang Create date: Aug 12, 2013
 */
package edu.sjtu.se.prophet.graph;

import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author deathspeeder
 * 
 */
public class Edge implements Serializable, Comparable<Edge> {
    /**
     * 
     */
    private static final long serialVersionUID = 5583333056691410771L;
    protected Node start;
    protected Node end;
    protected Map<String, Object> metrics = new TreeMap<String, Object>();

    public Edge(Node start, Node end) {
        this.start = start;
        this.end = end;
    }

    @Override
    public int compareTo(Edge o) {
        return this.hashCode() - o.hashCode();
    }

    @Override
    public String toString() {
        return start.getId() + "->" + end.getId();
    }

    @Override
    public int hashCode() {
        return start.hashCode() + 31 * end.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj instanceof Edge) {
            Edge edge = (Edge) obj;
            return edge.start.equals(start) && edge.end.equals(end);
        }
        return false;
    }

    public Node getStart() {
        return start;
    }

    public void setStart(Node start) {
        this.start = start;
    }

    public Node getEnd() {
        return end;
    }

    public void setEnd(Node end) {
        this.end = end;
    }

    public Map<String, Object> getMetrics() {
        return metrics;
    }

    public void setMetrics(Map<String, Object> metrics) {
        this.metrics = metrics;
    }

}
